package com.xsmart.goods.dao.wx;

import com.baomidou.mybatisplus.plugins.pagination.Pagination;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
public interface WxGoodsShopDao {

    /**
     * 查询店铺商品分类列表
     * @param ruId
     * @return
     */
    @Select("<script>" +
            "SELECT DISTINCT t4.cat_name, t4.cat_id, t1.id " +
            "FROM seller_shopinfo t1 " +
            "LEFT JOIN user_seller_goods t2 ON t1.id = t2.id " +
            "LEFT JOIN goods t3 ON t2.goods_id = t3.goods_id " +
            "LEFT JOIN category t4 on t3.cat_id = t4.cat_id " +
            "where ru_id = #{ruId}" +
            "</script>")
    List<Map<String, Object>> queryShopCategory(@Param("ruId") Integer ruId);

    @Select("<script>" +
            "SELECT t1.*, t2.goods_number, t2.goods_img, " +
            "CAST(IFNULL((SELECT sum(og.goods_number) FROM order_goods og " +
            "WHERE og.goods_id = t2.goods_id " +
            "and exists(select * from order_info oi " +
            "where oi.order_id = og.order_id and oi.order_status=1)),0) AS CHAR) good_sales, " +
            "CAST(IFNULL((SELECT sum(og.goods_number) FROM order_goods og " +
            "WHERE og.goods_id = t2.goods_id " +
            "and exists(select * from order_info oi " +
            "where oi.order_id = og.order_id and oi.order_status=1 " +
            "and exists(select * from infu_distributor_member dm " +
            "where dm.user_id = oi.user_id and dm.d_user_id=#{shopGoodsMap.user_id}))),0) AS CHAR) dis_sales " +
            "FROM user_seller_goods t1 " +
            "LEFT JOIN goods t2 ON t1.goods_id = t2.goods_id " +
            "where t2.cat_id = #{shopGoodsMap.cat_id} and t1.id = #{shopGoodsMap.id}" +
            "</script>")
    List<Map<String, Object>> queryShopGoodsList(Pagination page, @Param("shopGoodsMap")Map<String, Object> shopGoodsMap);
}
